package ktc.cn.ktc_base.controller;

import ktc.cn.ktc_base.Service.TbLabelService;
import ktc.cn.ktc_base.entity.TbLabel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;
import wfw.cn.ktc_common.entity.Result;
import wfw.cn.ktc_common.entity.StatusCode;

import java.io.StringReader;
import java.util.List;

@RestController
@RequestMapping("/label")
public class TbLabelController {

    @Autowired
    TbLabelService service;

    @RequestMapping(method = RequestMethod.POST)
    public Result add(@RequestBody TbLabel label){
        service.add(label);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public Result update(@PathVariable String id, @RequestBody TbLabel label) {
        label.setId(id);
        service.update(label);
        return new Result(true, StatusCode.OK, "修改成功");
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Result deletByID(@PathVariable String id){
        service.deletById(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Result findByID(@PathVariable String id){
        TbLabel label = service.findById(id);
        return new Result(true,StatusCode.OK,"查询成功",label);
    }

    @RequestMapping(method = RequestMethod.GET)
    public Result findAll(){
        List<TbLabel> labels = service.findAll();
        return new Result(true,StatusCode.OK,"查询成功",labels);
    }



}
